Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
Why expect({"[\"": 2}).toHaveProperty("[\"") is not true in jest?

I would like to test that object has a property with the name ["

In node js I can definie object "x" with property "[\""

> x = {"[\"": 2}
{ '["': 2 }
> x["[\""]
2

and of course

> '["' ===  "[\""
true

but when I typed test

expect({"[\"": 2}).toHaveProperty("[\"")

I received error:

Error: expect(received).toHaveProperty(path)

Expected path: "[\""
Received path: []

Received value: {"[\"": 2}

These versions also not works

expect({"[\"": 2}).toHaveProperty(`["`);
const p = `["`;
expect({[p]: 2}).toHaveProperty(p);

Update 1

There was a hypothesis that it is because of libraries

"esbuild-jest": "^0.5.0",
"esbuild-node-tsc": "^1.8.5",
"jest-text-transformer": "^1.0.2",

But I created pure js project with only jest@^27.5.1 installed and reproduced it

enter image description here

Update 2

There was a hypothesis that it depends on the operating system. I reproduced it on Macbook Pro and Arch Linux. For node js versions 12, 14, 16.

Working workaround:

expect({"[\"": 2}[`["`]).toBeDefined();
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda